const Big = require('./big.js');
function cal(expStr){

    //处理加减乘除
    let item=''
    let list=[]
    for(let i=0; i<expStr.length; i++){
        if(/[\d\.]/.test(expStr[i])){
            item=item+expStr[i]
        }else{
            if(item){
                list.push(item)
                item=''
            }
            list.push(expStr[i])
        }
    }
    if(item){
        list.push(item)
        item=''
    }
    let nList=[]

    for(let i=0;i<list.length;i++){
        const lastItem=nList[nList.length-1]
        if(list[i]==='-'&&/-?[\d\.]+/.test(list[i+1])&&!lastItem instanceof Big){
            nList.push(new Big(-parseFloat(list[i+1])))
            i++
        }else if(list[i]==='%'&& lastItem instanceof Big){
            nList[nList.length-1]=lastItem.div(100)
        }else if(/[\d\.]+/.test(list[i])){
            nList.push(new Big(list[i]))
        }else{
            nList.push(list[i])
        }
    }
    list=nList
    nList=[]
    for(let i=0;i<list.length;i++){
        if(list[i] instanceof Big&&list[i+1]==='×'&&list[i+2] instanceof Big){
            nList.push(list[i].times(list[i+2]))
            i=i+2
        }else{
            nList.push(list[i])
        }
    }
    list=nList

    nList=[]
    for(let i=0;i<list.length;i++){
        if(list[i] instanceof Big&&list[i+1]==='÷'&&list[i+2] instanceof Big){
            nList.push(list[i].div(list[i+2]))
            i=i+2
        }else{
            nList.push(list[i])
        }
    }
    list=nList
    nList=[]
    for(let i=0;i<list.length;i++){
        if(list[i] instanceof Big&&list[i+1]==='+'&&list[i+2] instanceof Big){
            nList.push(list[i].plus(list[i+2]))
            i=i+2
        }else{
            nList.push(list[i])
        }
    }
    list=nList
    nList=[]
    for(let i=0;i<list.length;i++){
        if(list[i] instanceof Big&&list[i+1]==='-'&&list[i+2] instanceof Big){
            nList.push(list[i].minus(list[i+2]))
            i=i+2
        }else{
            nList.push(list[i])
        }
    }
    list=nList
    return list

}
console.log(cal('2×5×3'))